package weaver.formmode.customjavacode.modeexpand.crm;

import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.cese.duss.ceseutil.OcrUitl;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-12-24
 * @Description:发票验真
 * @ModifyLog:
 **/

public class WeaInvoiceVerifiedAction extends AbstractModeExpandJavaCodeNew {
    /**
     * 执行模块扩展动作
     *
     * @param param param包含(但不限于)以下数据
     *              user 当前用户
     *              importtype 导入方式(仅在批量导入的接口动作会传输) 1 追加，2覆盖,3更新，获取方式(int)param.get("importtype")
     *              导入链接中拼接的特殊参数(仅在批量导入的接口动作会传输)，比如a=1，可通过param.get("a")获取参数值
     *              页面链接拼接的参数，比如b=2,可以通过param.get("b")来获取参数
     * @return
     */
    public Map<String, String> doModeExpand(Map<String, Object> param) {
        BaseBean baseBean = new BaseBean();
        Map<String, String> result = new HashMap<String, String>();
        try {
            baseBean.writeLog( "-------WeaInvoiceVerifiedAction---------" );
            User user = (User) param.get( "user" );
            int billid = -1;//数据id
            int modeid = -1;//模块id
            RequestInfo requestInfo = (RequestInfo) param.get( "RequestInfo" );
            if (requestInfo != null) {
                billid = Util.getIntValue( requestInfo.getRequestid() );
                modeid = Util.getIntValue( requestInfo.getWorkflowid() );
                if (billid > 0 && modeid > 0) {
                    baseBean.writeLog( "billid=" + billid );
                    baseBean.writeLog( "modeid=" + modeid );
                    //------请在下面编写业务逻辑代码------
                    RecordSet rs = new RecordSet();
                    String sql = "select fplx,fpdm,fphm,fprq,je,checkCode,sellerRegisterNum from uf_fpxx where id='" + billid + "'";
                    rs.executeQuery( sql );
                    rs.next();
                    String fplx = Util.null2String( rs.getString( "fplx" ) );
                    String newFplx = getTicketType( fplx );
                    String fpdm = Util.null2String( rs.getString( "fpdm" ) );
                    String fphm = Util.null2String( rs.getString( "fphm" ) );
                    String fprq = Util.null2String( rs.getString( "fprq" ) );
                    String je = Util.null2String( rs.getString( "je" ) );
                    String checkCode = Util.null2String( rs.getString( "checkCode" ) );
                    String sellerRegisterNum = Util.null2String( rs.getString( "sellerRegisterNum" ) );//预留电话
                    if (!"0".equals( fplx )) {
                        OcrUitl.invoicerecertify( newFplx, fpdm, fphm, fprq, je, checkCode, sellerRegisterNum,"" );
                    }
                }
            }
        } catch (Exception e) {
            result.put( "errmsg", "自定义出错信息" );
            result.put( "flag", "false" );
        }
        return result;
    }
    //获取验真发票类型
    public static String getTicketType(String invoiceType) {
        String newinvoiceType = "";
        if ("0".equals( invoiceType )) {
            newinvoiceType = "04";//增值税普通发票
        } else if ("1".equals( invoiceType )) {
            newinvoiceType = "01";//增值税专用发票
        } else if ("14".equals( invoiceType )) {
            newinvoiceType = "10";//增值税电子普通发票
        }
        return newinvoiceType;
    }
}
